<?php

use yii\helpers\Html;
use yii\grid\GridView;
use yii\helpers\Url;
/* @var $this yii\web\View */
/* @var $searchModel common\models\PostsSearchModel */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '内容管理';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="posts-model-index">


    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            'id',
            'title'=>[
                    'attribute'=>'title',
                    'format'=>'raw',
                    'value'=>function($model){
                        return '<a href="http://www.yiibo.com'.Url::to(["posts/view","id"=>$model->id]).'">'.$model->title.'</a>';
                }
            ],
            'summary',
//            'content:ntext',
//            'label_img',
            'cat.cat_name'=>[
                'attribute'=>'cat_id',
                'value'=>function($model){
                    return $model->cat['cat_name'];
                },
                'filter'=>false,
            ],
            //'user_id',
            'user_name',
            'is_valid'=>[
                'attribute'=>'is_valid',
                'value'=>function($model){

                    return $model->is_valid==1?'有效':'无效';
                },
                'filter'=>['1'=>'有效','0'=>'无效',],
            ],
            'created_at:datetime',
            //'updated_at',

            ['class' => 'yii\grid\ActionColumn'],
        ],
    ]); ?>


</div>
